 // 通过class获取元素
 function getByClass(oparent,sclass){
			 var oElm=oparent.getElementsByTagName('*');
			 var result=[];
			 var rg=new RegExp('\\b' +sclass +'\\b','i');
			 
			 for (var i=0;i<oElm.length;i++){
				 if(rg.test(oElm[i].className)){
					 result.push(oElm[i])
					 }
				 
				 }
		         return result;
		}

//后缀名截取函数
function subfix (filepath) {
	var  filefix = filepath.substring(filepath.lastIndexOf('.')+1);
	return filefix;
}
//判断是否符合规定的文件格式
/**
 * [[Description]]  截取指定文件的后缀名
 * @param   {[[Type]]} 要截取的文件路径 [[Description]]
 * @returns {Boolean} 截取后的结果 [[Description]]
 */
function is_allowType(filefix){
	 var allowReg = /jpg|jpeg|gif|png/;
	 if(allowReg.test(filefix)){
	 	  return true;
	 }else{
	 	  return false;
	 }
}

//得到文件域路径
function preview(file,prevbox,className){if(file.files&&file.files[0]){var reader=new FileReader();reader.onload=function(evt){prevbox.innerHTML="<img class="+className+' src="'+evt.target.result+'" />'};reader.readAsDataURL(file.files[0])}else{prevbox.innerHTML="<div class="+className+" style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src='"+file.value+"'\"></div>"}}

//创建背景遮罩层
function createLayout(){
        var body = document.body;
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
         // 创建背景层
         var layout = document.createElement("div");
         /*计算屏幕高宽*/
         var winscreenW = document.body.clientWidth;
         var winscreenH = document.body.clientHeight;
         layout.className = "layout";
         layout.style.top = scrollTop +'px';
         layout.style.width = winscreenW+'px';
         layout.style.height = winscreenH+'px';  
         body.appendChild(layout);
}

 //取消事件冒泡；
function stopBubble(e){
  //一般用在鼠标或键盘事件上
  if(e && e.stopPropagation){
  //W3C取消冒泡事件
  e.stopPropagation();
  }else{
  //IE取消冒泡事件
  window.event.cancelBubble = true;
  }
  };


function getlen(str,ch){
  var ret=0;
  for(var i=0;i<str.length;i++){if(str.charAt(i)==ch)	  ret++;}
  return ret;
}

//赞动画函数
function dropAnminials(pobj){
    // 创建动画盒子
    var span = document.createElement('span');
    var spanb = document.createElement('b');
    span.className = 'dropAnimals';
    span.innerHTML = "+";
    spanb.innerHTML = 1;
    span.appendChild(spanb);
    pobj.appendChild(span);
    var iNum = 1;
    var t;
    //开启动画
    t = setInterval(function(){
    	if(iNum>25){
            clearInterval(t); 
             pobj.removeChild(span);  
        }else{
        	iNum+=1;
        }
        span.style.top = -iNum +'px';
    },60)    	 
}

function mouseover(a,e,func){
     e = window.event || e;
     var b = e.fromElement || e.relatedTarget;

     mouseoverAndout(a,b,func);
}

function mouseout(a,e,func){
     e = window.event || e;
     var b = e.toElement || e.relatedTarget;

     mouseoverAndout(a,b,func);
}

function mouseoverAndout(a,b,func){
    if(document.all){
          if(!(a.contains(b))){
                   
                   func();

          }
    }else{
        var res = a.compareDocumentPosition(b);

        if(!(res==20 || res == 0)){
            func();
        }
    }
}

/**
 * 表单为空判断函数
 * @param  {[type]} $formArr 表单对象
 * @return {[bool]}          
 */
function checkFormINput($formArr){

    var num = 0;
    var FormErrorId = [];
    for(var i=0;i<$formArr.length;i++){
             if($formArr[i].value != ''){
                      num++;
             }else{
                    FormErrorId.push(i);
             }
    }
    //将错误的表单用红色框标出
    if(FormErrorId.length != 0){
      for(var i=0;i<FormErrorId.length;i++){
              $formArr[FormErrorId[i]].style.borderColor = "red";
      }
    }
    
    if(num==$formArr.length){
          return true;
    }else{
          return false;
    }
}


//单选 或 多选
/**
 * [[Description]] 单选 或 多选
 * @param {[[Type]]} obj  [[Description]] 触发对象
 * @param {[[Type]]} type [[Description]] 单选 0r 多选 s = 单选  m = 多选
 * @param {[[Type]]} num  [[Description]] 是否限制选择个数，为空则不限制
 * @param {[[return]]} 无
 */
function selTab(obj,type,num){
     var objLength = obj.length;
     var parNode = obj[0].parentNode;
     var input = parNode.getElementsByTagName('input');
    //单选
    if(type=="s"){

        for(var i=0;i<objLength;i++){
              obj[i].index = i;
              obj[i].onclick = function(){
                  //oldClass
                  var oldClass = this.className;
                  for(j=0;j<objLength;j++){
                         input[j].checked = false;
                         obj[j].className = oldClass;
                         obj[j].style.color = "#A8ABB7";
                  }
                  input[this.index].checked= true;
                  this.className = oldClass+" checked";
                  this.style.color = "#fff"             
              }
        }
    }
    
    if(type=="m"){
        
         if(num==undefined){
//               无限制选单
              for(var i=0;i<objLength;i++){
                  
                  obj[i].index = i ;
                  
                  obj[i].onclick = function(){
                       if(this.className.indexOf(" checked")!="-1"){
                          oldClass = this.className.substr(0,this.className.lastIndexOf(' checked'))
                       }else{
                          oldClass = this.className;
                       }
                      if(this.className != oldClass+" checked"){
                        input[this.index].checked = true;
                        this.className = this.className+" checked";
                        this.style.color = "#fff"
                      }else{
                        input[this.index].checked = false;
                        var classStyle = this.className.substr(0,this.className.lastIndexOf(' checked'))
                        this.className = classStyle;
                        this.style.color = "#A8ABB7"
                      }
                  
                  }
              
              
              }
             
         
         
         }else{
             //有限制条件
             checkNum = 0;
             
             for(var i=0;i<objLength;i++){
                  
                  obj[i].index = i ;
                  
                  obj[i].onclick = function(){
                       if(this.className.indexOf(" checked")!="-1"){
                          oldClass = this.className.substr(0,this.className.lastIndexOf(' checked'))
                       }else{
                          oldClass = this.className;
                       }
                      if(this.className != oldClass+" checked"){
                        if(checkNum!=num){
                            input[this.index].checked = true;
                            this.className = this.className+" checked";
                            this.style.color = "#fff"
                            checkNum++;
                        }
                      }else{
                        input[this.index].checked = false;
                        var classStyle = this.className.substr(0,this.className.lastIndexOf(' checked'))
                        this.style.color = "#A8ABB7"
                        this.className = classStyle;
                          checkNum--;
                      }
                  
                  }
              
              
              }
             
         }
    }
}

/**
 * 获取对象距body的距离
 * @param  {[type]} obj 对象
 * @return {[string]}     返回距body的边距
 */
function getPoint(obj) { //获取某元素以浏览器左上角为原点的坐标 
    var t = obj.offsetTop; //获取该元素对应父容器的上边距 
    var l = obj.offsetLeft; //对应父容器的上边距 
    //判断是否有父容器，如果存在则累加其边距 
    while (obj = obj.offsetParent) {//等效 obj = obj.offsetParent;while (obj != undefined) 
        t += obj.offsetTop; //叠加父容器的上边距 
        l += obj.offsetLeft; //叠加父容器的左边距 
    }
    Point = [l,t];
    return Point;

    alert("top: " + t + " left: " + l); 
}

/**
 * 添加收藏
 */
function addFavorite(thisobj,className){
      var id = thisobj.getAttribute('data');
      var url = FaviteURL +"?id="+id;
      ajax({
          type:"GET",
          url:url,
          dataType:"text",
          success:function(data){
                //进行DOM操作
                //收藏成功
                if(data==1){
                   if(className){
                       thisobj.className = className;
                   }
                }else{
                     alert('您已经收藏了该歌曲');
                }
          }
      })
}

/**
 * 取消收藏
 */
function cancelFavite(thisObj,id){
     var listCon = $('listCon');
     var url = cancelUrl+"?id="+id;
     ajax({
        type:"GET",
        url:url,
        dataType:"text",
        success:function(data){
             if (data==1) {
                  var parent = thisObj.parentNode.parentNode
                  listCon.removeChild(parent);
             }else{
                  alert('取消收藏失败，请重试……');
             }
        }
     })
}

/**
 * 批量删除
 */
function DeletionByQuery(){
     var DeletionByQueryId = [];
     var listConInp = $('listCon').getElementsByTagName('input');
     for (var i = 0; i < listConInp.length; i++) {
         if (listConInp[i].checked == true) {
                var id = listConInp[i].value;
                 DeletionByQueryId.push(id);
         };
     };
     var liststr = DeletionByQueryId.join(',');
     var Url = cancelUrl+"?id="+liststr;
     ajax({
        type:'GET',
        url:Url,
        dataType:'text',
        success:function(data){
            if (data) {
                  // 倒序删除
                  for (var i = listConInp.length-1; i >=0; i--) {
                        if(listConInp[i].checked == true){
                                parent = listConInp[i].parentNode;
                                $('listCon').removeChild(parent);
                        }
                  };
                  var CountNum = getByClass(document,'select')[0].getElementsByTagName('b')[0];
                  CountNum.innerHTML = parseInt(CountNum.innerHTML)-DeletionByQueryId.length;
            };
        }
     })
}

/**
 * 全选
 */
function selectAll(thisObj){
    var listConInp = $('listCon').getElementsByTagName('input');
    if(thisObj.checked == true){
            for (var i = 0; i < listConInp.length; i++) {
                 listConInp[i].checked = true;
            };
    }else{
           for (var i = 0; i < listConInp.length; i++) {
                 listConInp[i].checked = false;
            }; 
    }
}

/**
 * 打印对象
 * @param  {[type]} obj 对象
 */
function writeObj(obj){ 
    var description = ""; 
    for(var i in obj){   
        var property=obj[i];   
        description+=i+" = "+property+"\n";  
    }   
    alert(description); 
} 
// 写cookie
function setCookie(name,value) 
{ 
    var Days = 30; 
    var exp = new Date(); 
    exp.setTime(exp.getTime() + Days*24*60*60*1000); 
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
} 

//获取cookie
function getCookie(name) 
{ 
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
    if(arr=document.cookie.match(reg))
 
        return unescape(arr[2]); 
    else 
        return null; 
} 

// 获取json长度
function getJsonLength(jsonData){

var jsonLength = 0;

for(var item in jsonData){

jsonLength++;

}

return jsonLength;

}


/**
 * 分享框展示
 */
function showShareDaig(){

     //创建遮罩层
     var ScreenWidth = document.body.clientWidth;
     var ScreenHeight = document.documentElement.clientHeight;
     var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
     var layout = document.createElement('div');
     layout.id = 'layout';
     layout.style.height = ScreenHeight+scrollTop+'px';

     var share = document.createElement('div');
     share.id = 'share';
     l = (ScreenWidth-490)/2;
     t = (ScreenHeight-180)/2+scrollTop;
     share.style.cssText = "left:"+l+"px;top:"+t+'px';
     var HTML = "<span class='close' onclick='closeShare()'></span><div id='sharebox'>分享到: <a href='' class='shareIcon qqzone' title='QQ空间'></a><a href='' class='shareIcon sinaweibo' title='新浪微博'></a><a href='' class='shareIcon qqweibo' title='腾讯微博'></a><a href='' class='shareIcon baidu' title='百度'></a><a href='' class='shareIcon renren' title='人人网'></a><a href='' class='shareIcon kaixin' title='开心网'></a></div><div id='shareInfo'><p>生成mp3外链，将歌曲设置成为您的QQ空间背景音乐：</p><a href=''>获取外链</a></div>"
     share.innerHTML = HTML;
     //添加到body
     document.body.appendChild(layout);
     document.body.appendChild(share);
}

/**
 * 关闭分享框
 */
function closeShare(){
     var layout = document.getElementById('layout');
     var share = document.getElementById('share');
     Move(share,'opacity',0);
     Move(layout,'opacity',0);
     setTimeout(function(){
       document.body.removeChild(share);
       document.body.removeChild(layout);
   },500);

}

 /**
  * 全选
  * @param 表单盒子
  */
 function selAll(inputbox) {
      var inpEle = $('siteMessWrap').getElementsByTagName('input');
      if(this.checked==true) {
          this.checked = false;
      }else{
          this.checked = true;
      }
      for(var i=0;i<inpEle.length;i++){
           inpEle[i].checked = this.checked;
      }

 }


 /**
  * 格式化查询字符串(正则实现)
  * @param url url地址
  * @return {Object} 格式化的json对象
  */
 function formatUrl(url){
     var reg=/(?:[?&]+)([^&]+)=([^&]+)/g;
     var data={};
     function fn(str,pro,value){
         data[decodeURIComponent(pro)]=decodeURIComponent(value);
     }
     url.replace(reg,fn);
     return data;
 }